#include "config.h"

Config::Config()
{
    portSettingFileName = "port.conf";
    portOptionsFileName = "serialOptions.dat";
}

QPair<QString, QString> Config::getPortConfig(){
    QPair<QString, QString> portSetting;

    QFile dataFile(portSettingFileName.toUtf8().constData());
        if (dataFile.open(QIODevice::ReadOnly))
        {
           QTextStream in(&dataFile);
           portSetting.first = in.readLine();
           portSetting.second = in.readLine();

           dataFile.close();
        }

    return portSetting;
}

QList<QString> Config::getPortDevice(){
    QList<QString> portDeviceList;
    bool found = false;

    QFile dataFile(portOptionsFileName.toUtf8().constData());
        if (dataFile.open(QIODevice::ReadOnly))
        {
           QTextStream in(&dataFile);
           while (!in.atEnd())
           {
              QString line = in.readLine();

              if(line == "[/portDevice]") found = false;

              if(found) portDeviceList.append(line);

              if(line == "[portDevice]") found = true;
           }
           dataFile.close();
        }

    return portDeviceList;
}

bool Config::existPortConfig(){
    return QFile::exists(portSettingFileName);
}

bool Config::existPortOptions(){
    return QFile::exists(portOptionsFileName);
}
